Welcome To
Selection
Statements


Decision Making Statements

The Decision making statements is a one type of control flow statements. it is also called branching statements or selection statements. the computer takes the decision which statements get executed . the computer decide the which statement is execute first. there are four types of if conditions.

  • Simple if Statement
  • If Else Statement
  • If elif Else Statement
  • Nested if Statement
  • Simple If Statements

    The simple if statement is a condition based statements . and one way decision making statement. it have single if condition and one single statement based on condition the statement get executed. if condition is true then the statement one will executed otherwise next condition is .

    Syntax

    If condition:
          Statement

    FlowChart

    Condition Statement 3 Statement 2 Statement 1 True False

    Example

    X=10
    if x>5:
         print("x is greater then 5")

    IF Else statement

    It Is a another decision making statement. if condition is true then the statement block will be executed otherwise else statement block will be executed two way decision making statement.

    Syntax

    if condition:
          Statement true
    Else:
         Statement false

    Flowchart

    Condition Next True Statement block False statemant block False True

    Example

    x=10
    y=5
    if x>y:
          print(" X is greater then y")
    else:
         print("x is less then y")

    If Elif Else

    This is the multi way decision making statement. which have multiple conditions in sequence . based on conditions the stements get executed. if condition 1 is true then the statement 1 get executed otherwise it moves into condition 2 . if condition 2 is true then the statement get executed otherwise the next condition means the evaluate condition n-1 is true then the true statement is executed otherwise the false statement get executed. the Examples in the below.

    Syntax

    if condition1:
         statement1
    elif condition2:
          statement2
    elif condition n-1:
         statement n-1
    else:
          statement n

    Flowchart

    > Statement1 Statement2 > > > condition 1 Condition 2 condition n-1 Statement n-1 > Statement n End Statement2 >Statement1 condition 1 Condition 2 condition n-1 Statement n-1 > Statement n End True False True False True False

    Example

    marks=int(input("Enter your marks"))
    if marks>86 and Marks<=90:
         print("A Grade")
    elif marks>65 and marks<=85:
        print("B grade")
    elif marks>45 and marks<=64:
        print("c grade")
    else:
        print("Fail")

    Nested if statement

    The nested if statement is a one type of decision making statement the program mean the python program can have if within another if condition is called nested is statement and if condition1 is true then the condition2 will get evaluated other wise the condition3 is evaluated. if condition2 is true then then the true statement get executed otherwise the else statement get executed. Example in the below

    Syntax

    if Condition1:
        if condition2:
           statement true
        else:
           Statement false
    else:
        if condition3:
           statement true
       else:
            statement false

    FlowChart

    condition 1 Condition 3 condition 2 End statement statement statement statement True False True False True False

    Example

    number=int(input("Enter a number"))
    if number%2=0:
        if number%2==0:
            print("The Given number is odd")
        else:
            print("The given number is not odd")
    else:     if number%1=0:
            print("The given number is Even")
        else:
            print("The given nuber is not even")